{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# hvPlot.quadmesh\n",
    "\n",
    "```{eval-rst}\n",
    ".. currentmodule:: hvplot\n",
    "\n",
    ".. automethod:: hvPlot.quadmesh\n",
    "```\n",
    "\n",
    "## Backend-specific styling options\n",
    "\n",
    "```{eval-rst}\n",
    ".. backend-styling-options:: quadmesh\n",
    "```\n",
    "\n",
    "## Examples\n",
    "\n",
    "### Basic quadmesh plot\n",
    "\n",
    "We generate a dummy dataset with an irregular grid. `colorbar` is True by default."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.xarray  # noqa\n",
    "import numpy as np\n",
    "import xarray as xr\n",
    "\n",
    "np.random.seed(42)\n",
    "# Irregular grid\n",
    "x = np.sort(np.random.uniform(0, 10, size=40))\n",
    "y = np.sort(np.random.uniform(0, 5, size=30))\n",
    "X, Y = np.meshgrid(x, y)\n",
    "data = np.sin(X) * np.cos(Y) * 3\n",
    "ds = xr.Dataset({\"value\": ([\"y\", \"x\"], data)}, coords={\"y\": y, \"x\": x})\n",
    "\n",
    "ds.hvplot.quadmesh(x='x', y='y', cmap='viridis')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Use of `groupby`\n",
    "\n",
    "When the grid has more dimensions, like `time` in the example below, widgets are automatically created to explore further the dataset. This is equivalent to setting the [`groupby`](option-groupby) to the remaining dimension(s)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.xarray  # noqa\n",
    "\n",
    "ds = hvplot.sampledata.air_temperature(\"xarray\").isel(time=[0, 1])\n",
    "\n",
    "ds.hvplot.quadmesh(\n",
    "    x=\"lon\", y=\"lat\", z=\"air\", groupby=\"time\",\n",
    "    frame_width=400, data_aspect=1, dynamic=False,\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Use of `logz`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.xarray  # noqa\n",
    "import numpy as np\n",
    "import xarray as xr\n",
    "\n",
    "np.random.seed(42)\n",
    "x = np.sort(np.random.uniform(0, 10, size=40))\n",
    "y = np.sort(np.random.uniform(0, 5, size=30))\n",
    "X, Y = np.meshgrid(x, y)\n",
    "data = np.exp(np.sin(X) * np.cos(Y) * 3) * 100\n",
    "ds = xr.Dataset({\"value\": ([\"y\", \"x\"], data)}, coords={\"y\": y, \"x\": x})\n",
    "\n",
    "ds.hvplot.quadmesh(logz=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Multidimensional coordinates\n",
    "\n",
    "You can plot irregular grids defined by multidimensional coordinates."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.xarray  # noqa\n",
    "import numpy as np\n",
    "import xarray as xr\n",
    "\n",
    "np.random.seed(42)\n",
    "lon, lat = np.meshgrid(np.linspace(-20, 20, 5), np.linspace(0, 30, 4))\n",
    "lon += lat / 10\n",
    "lat += lon / 10\n",
    "da = xr.DataArray(\n",
    "    np.arange(20).reshape(4, 5),\n",
    "    dims=[\"y\", \"x\"],\n",
    "    coords={\"lat\": ((\"y\", \"x\"), lat), \"lon\": ((\"y\", \"x\"), lon)},\n",
    ")\n",
    "\n",
    "da.hvplot.quadmesh(x=\"lon\", y=\"lat\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Geographic plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cartopy.crs as ccrs\n",
    "import hvplot.pandas  # noqa\n",
    "\n",
    "ds = hvplot.sampledata.air_temperature(\"xarray\").isel(time=0)\n",
    "\n",
    "ds.hvplot.quadmesh(\n",
    "    x=\"lon\", y=\"lat\", geo=True, coastline=True,\n",
    "    projection=ccrs.LambertConformal(central_longitude=-95, central_latitude=35)\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Image vs. Quadmesh\n",
    "\n",
    "See the [`image` reference page](image-vs-quadmesh) for more information about the differences between `quadmesh` and `image`."
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
